<template>
  <div class="container">
    <div class="list-container">
      <van-pull-refresh v-model="refreshing" v-model:loading="loading" @refresh="onRefresh">
        <van-list
          v-model:loading="loading"
          :finished="finished"
          finished-text="没有更多了"
          @load="getList"
        >
          <van-cell v-for="item in list" :key="item"  :title="item.day"/>
        </van-list>
      </van-pull-refresh>
    </div>
  </div>
</template>

<script setup>

import {  onMounted, reactive, ref, toRaw } from 'vue'
import { holidaysApi } from '@/api/workLog.js'

const queryParams = reactive({
  pageNum: 1,
  pageSize: 20
})
const list = ref([])
const loading = ref(false)
const finished = ref(false)
const refreshing = ref(false)

const getList = () => {

  let params = toRaw(queryParams)
  holidaysApi(toRaw(params)).then(res => {
    if (refreshing.value) {
      list.value = []
      refreshing.value = false
    }
    list.value = [...list.value, ...res.rows]
    loading.value = false
    // 判断是否加载完成
    if(res.rows.length < params.pageSize){
      finished.value = true
    }else{
      queryParams.pageNum = queryParams.pageNum + 1
    }
  })
}

const onRefresh = () => {
  // 清空列表数据
  finished.value = false
  // 将 loading 设置为 true，表示处于加载状态
  loading.value = true
  getList()
}
const init = () => {
  // getList()
}

onMounted(() => {
  init()
})
</script>

<style scoped lang="less">
.container {
  width: 100vw;
  height: 100%;
  overflow-y: auto;
}

.date-picker-box {
  height: 500px;
}
</style>